﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL;

namespace logic
{
    public class order
    {
        public static int insert(OrderEntity _order)
        {
           return  Order.insert(_order);
        }
        public static int insertWithDynamicOrder(OrderEntity order)
        {
            return Order.insertWithDynamicOrder(order);
        }
        public static int insertDynamicOrder(OrderEntity order)
        {
            return Order.insertDynamicOrder(order);
        }

        public static DataSet select(string where, string orderby, int pagesize, int pageindex)
        {
            return DAL.DbHelper.ExecuteDataSetPageSize("orderid,orderno,sourceName,amount,companyNo,company,orderDt,receiveDt,statusName,updateStatusdt,adminName,customerid,source,username,serviceNote,standardAmount,closeReason,contact,contactMobile,contactPhone,areaName,address,note,status,companyId,fireightFee,taxfee,typeCount,enabledWeeklyPrice", "vw_Order_list", where, "orderid", orderby, pagesize, pageindex);
        }
        public static DataSet selectDynamicOrder(string where, string orderby, int pagesize, int pageindex)
        {
            return DAL.DbHelper.ExecuteDataSetPageSize("orderNo,amount,companyNo,company,orderDt,receiveDt,orderStatus,updateStatusdt,username,orderid,note,serviceNote,closeReason,status,contact,contactMobile,contactPhone,address,areaName", "vw_DynamicOrder_list", where, "orderid", orderby, pagesize, pageindex);
        }
        public static DataSet selectDynamicOrderItem(string where, string orderby, int pagesize, int pageindex)
        {
            return DAL.DbHelper.ExecuteDataSetPageSize("productNo,businessnatureName,name,initQuantity,unit,quantity,note,orderprice,nowprice,amount,oiid,orderId,productId,businessnature,customerId,sellerId,sellerPrice", "vw_DynamicOrderItem_list", where, "orderid", orderby, pagesize, pageindex);
        }
        public static OrderEntity getDynamicById(int orderid)
        {
            return Order.getDynamicById(orderid);
        }
        public static void update(OrderEntity _order)
        {
            Order.update(_order);
        }
        public static OrderEntity getById(int orderid)
        {
            return Order.getById(orderid);
        }

        public static DataRow getDetailByOrderId(int orderId)
        {
            return DbHelper.ExecuteDataRow("[dbo].[p_order_getDetailByOrderId]", orderId);
        }

        public static OrderEntity getByDynamicOrderId(int orderid)
        {
            return Order.getByDynamicOrderId(orderid);
        }
        public static void updateStatus(OrderEntity _order)
        {
            Order.updateStatus(_order);
        }
        public static void updateStatusDate(int orderId, DateTime updateStatusDt)
        {
            Order.updateStatusDate(orderId, updateStatusDt);
        }

        /// <summary>
        /// 给物流查看的订单列表并可导出Excel
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static DataTable listByImportExcel(string where)
        {
            return Order.listByImportExcel(where);
        }

        public static DataSet listWithPayable(string where, string orderby, int pagesize, int pageindex)
        {
            return DAL.DbHelper.ExecuteDataSetPageSize("*", "vw_Order_listWithPayable", where, "orderid", orderby, pagesize, pageindex);
        }

        /// <summary>
        /// 订单按月汇总
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public static DataTable listWithCollect(int companyId)
        {
            return Order.listWithCollect(companyId);
        }

        public static DataTable getTotal(string where)
        {
            return Order.getTotal(where);
        }
        public static void updateDynamicOrder(int orderId, string orderNo, int adminId)
        {
            Order.updateDynamicOrder(orderId, orderNo, adminId);
        }
        public static int dymanicOrderUnsale(string orderNo)
        {
            return Order.dymanicOrderUnsale(orderNo);
        }
        public static void updateDynamicOrderByService(OrderEntity order)
        {
            Order.updateDynamicOrderByService(order);
        }
        public static void updateDynamiceOrderByOrderId(int orderid,int adminid)
        {
            Order.updateDynamiceOrderByOrderId(orderid,adminid);
        }
        public static void closeDynamicOrder(int orderid, string closeReason)
        {
            Order.closeDynamicOrder(orderid, closeReason);
        }

        public static int countTodayDynamicOrder()
        {
            return Order.countTodayDynamicOrder();
        }
    }
}
